﻿@using SCMS.Resources
@model SCMS.UI.Models.ViewWRNDetails

<div class="partialViewCard">
    <div class="partialViewCardHeader">
        <h3>
            @Resources_morgan.WRForm_LoadWRF_WRO</h3>
    </div>
    @if (Model.CanApprove)
    {
        string linkText = null;
        string actionName = null;
        if (Model.EntityWHouseRelease.IsSubmitted && !Model.EntityWHouseRelease.IsApproved && Model.EntityWHouseRelease.IsRejected)
        {
            linkText = Resources_morgan.WRForm_ViewNRNDetails_ApproveWRO;
            actionName = "LoadWRO";
        }
        if (linkText != null)
        {
            <center>
                @Ajax.ActionLink(linkText, actionName, "RequestReview", new { id = "" }, new AjaxOptions
                {
                    OnBegin = "ShowDialogueOR('" + linkText + ": " + Model.EntityWHouseRelease.RefNumber + "')",
                    UpdateTargetId = "popup-page",
                    LoadingElementId = "popup-loading",
                    Url = Url.Action(actionName + "/" + Model.EntityWHouseRelease.Id, "RequestReview"),
                    OnSuccess = "CenterPopup"
                }) 
            </center>
        }
    }
    else if(!Model.EntityWHouseRelease.IsSubmitted)
    {
            <center>
                @Ajax.ActionLink(Resources_frank.WRForm_ViewNRNDetails_EditWRO, "LoadWRItems", new { id = "" }, new AjaxOptions
                {
                    UpdateTargetId = "wrfDiv",
                    LoadingElementId = "popup-loading",
                    Url = Url.Action("LoadWRItems/" + Model.EntityWHouseRelease.Id),
                    OnSuccess = "hidebutton('btnsave');"
                }) | 
                @Ajax.ActionLink(Resources_frank.WRForm_ViewNRNDetails_DeleteWRO, "DeleteWRO", new { id = "" }, new AjaxOptions
                {
                    UpdateTargetId = "wrfDiv",
                    LoadingElementId = "loading",
                    Url = Url.Action("DeleteWRO/" + Model.EntityWHouseRelease.Id),
                    OnSuccess = "if (document.getElementById('table') != null) {initSorter();sorter.size(50);}",
                    Confirm = string.Format(Resources_frank.Global_String_ConfirmDelete, Model.EntityWHouseRelease.RefNumber)
                })
            </center>
    }
    else
    {
        <br />
    }
    <h4 style="text-align: center;">@Model.EntityWHouseRelease.RefNumber</h4>
    <b style="font-weight: bold; font-size: 12px;">&nbsp;&nbsp;&nbsp;Requestor</b>
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th width="20%">
                @Resources_frank.Global_String_Name
            </th>
            <th width="20%">
                @Resources_morgan.Global_String_Title
            </th>
            <th width="20%">
                @Resources_frank.Global_String_Office
            </th>
            <th width="20%">
                @Resources_frank.Global_String_Signature
            </th>
            <th width="20%">
                @Resources_morgan.Global_String_RequestDate
            </th>
        </tr>
        <tr>
            <td align="center">
                @if (Model.EntityWHouseRelease.Staff1 != null)
                {
                    @Model.EntityWHouseRelease.Staff1.Person.FirstName
                    @Html.Raw("&nbsp;")
                    @Model.EntityWHouseRelease.Staff1.Person.OtherNames
                }
            </td>
            <td align="center">
                @if (Model.EntityWHouseRelease.Staff1 != null)
                {
                    @Model.EntityWHouseRelease.Staff1.Designation.Name
                }
            </td>
            <td align="center">
                @if (Model.EntityWHouseRelease.Staff1 != null)
                {
                    @Model.EntityWHouseRelease.Staff1.CountrySubOffice.Name
                }
            </td>
            <td align="center">
                @if (Model.EntityWHouseRelease.Staff1 != null && Model.EntityWHouseRelease.Staff1.Person.SignatureImage != null)
                {
                    <img src="@Url.Action("Photo", "Person", new { id = Model.EntityWHouseRelease.Staff1.Person.Id, area = "" })" alt="" style="max-width: 80px;" />
                }
            </td>
            <td align="center">
                @Model.EntityWHouseRelease.PreparedOn.ToString("dd/MM/yyyy h:mm tt")
            </td>
        </tr>
    </table>
    <br />
    <b style="font-weight: bold; font-size: 12px;">&nbsp;&nbsp;&nbsp;@Resources_frank.Global_String_ApprovedBy</b>
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th width="20%">
                @Resources_frank.Global_String_Name
            </th>
            <th width="20%">
                @Resources_morgan.Global_String_Title
            </th>
            <th width="20%">
                @Resources_frank.Global_String_Office
            </th>
            <th width="20%">
                @Resources_frank.Global_String_Signature
            </th>
            <th width="20%">
                @Resources_morgan.Global_String_RequestDate
            </th>
        </tr>
        <tr>
            <td align="center">
                @if (Model.EntityWHouseRelease.IsApproved && Model.EntityWHouseRelease.Staff != null)
                {
                    @Model.EntityWHouseRelease.Staff.Person.FirstName
                    @Html.Raw("&nbsp;")
                    @Model.EntityWHouseRelease.Staff.Person.OtherNames
                }
            </td>
            <td align="center">
                @if (Model.EntityWHouseRelease.IsApproved && Model.EntityWHouseRelease.Staff != null)
                {
                    @Model.EntityWHouseRelease.Staff.Designation.Name
                }
            </td>
            <td align="center">
                @if (Model.EntityWHouseRelease.IsApproved && Model.EntityWHouseRelease.Staff != null)
                {
                    @Model.EntityWHouseRelease.Staff.CountrySubOffice.Name
                }
            </td>
            <td align="center">
                @if (Model.EntityWHouseRelease.IsApproved && Model.EntityWHouseRelease.Staff != null && Model.EntityWHouseRelease.Staff.Person.SignatureImage != null)
                {
                    <img src="@Url.Action("Photo", "Person", new { id = Model.EntityWHouseRelease.Staff.Person.Id, area = "" })" alt="" style="max-width: 80px;" />
                }
            </td>
            <td align="center">
                @if (Model.EntityWHouseRelease.IsApproved && Model.EntityWHouseRelease.Staff != null)
                {
                    @Model.EntityWHouseRelease.ApprovedOn.Value.ToString("dd/MM/yyyy h:mm tt")
                }
            </td>
        </tr>
    </table>
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
        border-collapse: collapse; padding: 5px; font-size: 12px;">
        <tr class="gridheader">
            <th>
            </th>
            <th>
                @Resources_morgan.WRForm_LoadWRF_ItemGoodsDescription
            </th>
            <th>
                @Resources_morgan.Global_String_UnitMessure
            </th>
            <th>
                @Resources_morgan.Global_String_SerialNo
            </th>
            <th>
                @Resources_morgan.Global_String_AssetNo
            </th>
            <th>
                @Resources_morgan.Global_String_Quantity
            </th>
            <th>
                @Resources_morgan.Global_String_Comments
            </th>
        </tr>
        @{int x = 0; string rowClass = ""; int count = 0; string itemName, serialNo, AssetNo; }
        @foreach (var item in Model.writems)
        {
            if (x % 2 == 0) { rowClass = "grideven"; }
            if (x % 2 != 0) { rowClass = "gridodd"; }
            if (item.Inventory.Item.ItemCategory.CategoryCode == "C")
            {
                itemName = item.Inventory.Item.Name;
                serialNo = item.Inventory.Item.SerialNumber;
                AssetNo = @Resources_morgan.Global_String_NA;
            }
            else
            {
                itemName = item.Asset.Name;
                serialNo = item.Asset.SerialNumber;
                AssetNo = item.Asset.AssetNumber;
            }
            if (x >= 0) { x = x + 1; }
            count = count + 1;
            <tr class="gridodd">
                <td style="width: 5%; text-align: center;">
                    @count
                </td>
                <td style="width: 25%; text-align: left;">
                    @*@item.Inventory.Item.Name*@
                    @itemName
                </td>
                <td style="width: 13%; text-align: center;">
                    @item.Inventory.Item.UnitOfMeasure.Code
                </td>
                <td style="width: 15%; text-align: center;">
                    @*@item.Inventory.Item.SerialNumber*@
                    @serialNo
                </td>
                <td style="width: 15%; text-align: left;">
                    @*@item.Asset.AssetNumber*@
                    @AssetNo
                </td>
                <td style="width: 15%; text-align: center;">
                    @item.Quantity
                </td>
                <td style="width: 10%; text-align: left;">
                    @item.Comments
                </td>
            </tr>
        }
    </table>
    <br />
    @*<table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
        border-collapse: collapse; padding: 5px; font-size: 12px;">
        <tr>
            <td>
                Item/Goods released in Good Condition
                
            </td>
            <td>
                Item/Goods Released in Correct Qty
            </td>
            <td>
                Item/Goods not released
            </td>
        </tr>
    </table>*@ <b style="font-weight: bold; font-size: 12px;">&nbsp;&nbsp;&nbsp;Receipient</b>
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th width="33%">
                @Resources_frank.Global_String_Name
            </th>
            <th width="33%">
                @Resources_morgan.Global_String_Title
            </th>
            <th width="34%">
                @Resources_frank.Global_String_Office
            </th>
        </tr>
        <tr>
            <td align="center">
                @if (Model.EntityWHouseRelease.Staff2 != null)
                {
                    @Model.EntityWHouseRelease.Staff2.Person.FirstName
                    @Html.Raw("&nbsp;")
                    @Model.EntityWHouseRelease.Staff2.Person.OtherNames
                }
            </td>
            <td align="center">
                @if (Model.EntityWHouseRelease.Staff2 != null)
                {
                    @Model.EntityWHouseRelease.Staff2.Designation.Name
                }
            </td>
            <td align="center">
                @if (Model.EntityWHouseRelease.Staff2 != null)
                {
                    @Model.EntityWHouseRelease.Staff2.CountrySubOffice.Name
                }
            </td>
        </tr>
    </table>
    @*<br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
        border-collapse: collapse; padding: 5px; font-size: 12px;">
        <tr class="gridheader">
            <th colspan="4" align="left">
                &nbsp;&nbsp; Warehouse
            </th>
        </tr>
        <tr class="gridodd">
            <td style="width: 15%;">
                Name:
            </td>
            <td style="width: 30%;">
            </td>
            <td style="width: 15%;">
                Title:
            </td>
            <td style="width: 30%;">
            </td>
        </tr>
        <tr class="gridodd">
            <td>
                Date:
            </td>
            <td>
            </td>
            <td>
                Signature:
            </td>
            <td>
            </td>
        </tr>
    </table>*@
    <hr />
    @if (Model.EntityWHouseRelease.IsApproved)
    {
        <a class="btn btn-primary"  href="@Url.Action("ReleaseForm", "WareHouse", new { area = "Reports", WRNid = Model.EntityWHouseRelease.Id })" target="_blank" style="margin-left: 48%; margin-bottom: 2%;">
            @Resources_morgan.WRForm_ViewNRNDetails_GetPDFofWRN</a>
    }
    <br />
</div>
<br />
<p>
    @Html.ActionLink(Resources_frank.Global_String_BackToList, "Index")</p>
